package com.movie.service;

import com.movie.dto.MovieDTO;
import com.movie.entity.Movie;
import com.movie.mapper.MovieMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecommendService {

    @Autowired
    private MovieMapper movieMapper;

    public List<MovieDTO> recommendMoviesForUser(Integer userId) {
        // 查询用户最喜欢的电影类别
        String favCategory = movieMapper.findFavoriteCategoryByUser(userId);

        if (favCategory == null) {
            // 如果没有评分过，就推荐所有电影里评分最高的（默认剧情类）
            return movieMapper.findMoviesByCategoryExcludeRated("剧情", userId);
        }

        // 推荐该类别下评分高的电影（排除已经看过/评分过的）
        return movieMapper.findMoviesByCategoryExcludeRated(favCategory, userId);
    }
}
